//
//  THJContractShowVC.m
//  THJXHW
//
//  Created by 河南德艺 on 2018/9/5.
//  Copyright © 2018年 河南德艺. All rights reserved.
//

#import "THJContractShowVC.h"

@interface THJContractShowVC ()<UIWebViewDelegate>
{
    UIWebView * webview;
}
@end

@implementation THJContractShowVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self SVHUDShow];
    if(KIsiPhoneX){
        [self setXNavBarWithTitle:@"合同详情"];
    }else{
        [self setNavBarWithTitle:@"合同详情"];
    }
    webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, NavbarHeight, ScreenWidth, ScreenHeight - NavbarHeight)];
    [self.view addSubview:webview];
    NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"contract3.html" withExtension:nil];
    webview.delegate = self;
    NSURLRequest *request = [NSURLRequest requestWithURL:fileURL];
    [webview loadRequest:request];
    // Do any additional setup after loading the view from its nib.
}
- (void)webViewDidFinishLoad:(UIWebView *)webView {
    [self getData];
}
-(void)getData{
    NSLog(@"self.order:%@",self.orderId);
    NSDictionary * dic = @{@"id":[RSA encryptString:self.orderId publicKey:RSA_PubKey],@"type":@"ios"};
    [THJNetWork postNetDataFromUrl:@"http://p.thjb.net/thjblink/appdata.php?action=hetong_all_info" parameters:dic callback:^(NSDictionary *  receiveData, NSError *error) {
        NSLog(@"查看合同信息--%@",receiveData);
        [self SVHUDHiden];
        if([receiveData[@"status"] isEqual:@"success"]){
            [self setContractWithDic:receiveData[@"data"]];
        }else{
            [self HUDShowMsg:@"获取信息失败" AfterDelayDimiss:1];
        }
    }];
}
-(void)setContractWithDic:(NSDictionary*)dic{
//    NSLog(@"银行:%@",  [self DCRP_STR:dic[@"buyer_yinhang"]]);
//    NSLog(@"买受人检测:%@",  [self DCRP_STR:dic[@"buyer_truename"]]);
    NSString * yanshoubianzhun = dic[@"yanshoubiaozhun"];
    NSString * koufa = dic[@"fine_standard"];
    if([yanshoubianzhun isEqual:@""]){
        NSLog(@"空的");
        yanshoubianzhun = @"无";
    }
    if([koufa isEqual:@""]){
        NSLog(@"空的");
        koufa = @"无";
    }
    NSArray * arr = @[
                      @"buyer_name",
                      @"buyer_address",
                      @"buyer_corp",
                      @"buyer_deputy",
                      @"buyer_mobile",
                      @"buyer_account",
                      @"buyer_bank",
                      @"buyer_tax_number",
                      @"c_buyer",
                      @"c_seller",
                      @"c_tax",
                      @"c_pay_type",
                      @"c_gg",
                      @"c_delivery_type",
                      @"c_pack",
                      @"c_amount",
                      @"c_total_money",
                      @"c_notes",
                      @"c_standard",
                      @"c_penalty",
                      @"c_unit",
                      @"c_total_money_upper",
                      @"c_product_name",
                      @"c_date",
                      @"c_number",
                      @"seller_name",
                      @"seller_address",
                      @"seller_corp",
                      @"seller_deputy",
                      @"seller_mobile",
                      @"seller_account",
                      @"seller_bank",
                      @"seller_tax_number",
                      @"c_freight_pay"
                      ];
    NSArray * arr2 = @[
                       [self DCRP_STR:dic[@"buyer_truename"]],
                       [self DCRP_STR:dic[@"buyer_address"]],
                       [self DCRP_STR:dic[@"buyer_faren"]],
                       [self DCRP_STR:dic[@"buyer_dailiren"]],
                       [self DCRP_STR:dic[@"buyer_tel"]],
                       [self DCRP_STR:dic[@"buyer_accno"]],
                       [self DCRP_STR:dic[@"buyer_yinhang"]],
                       [self DCRP_STR:dic[@"buyer_shuihao"]],
                       [self DCRP_STR:dic[@"b_name"]],
                       [self DCRP_STR:dic[@"s_name"]],
                       [[self DCRP_STR:dic[@"hanshui"]] isEqual:@"1"]?@"含税":@"不含税",
                       [self DCRP_STR:dic[@"order_type"]],
                       [self DCRP_STR:dic[@"guige"]],
                       [[self DCRP_STR:dic[@"yunshu"]] isEqual:@"1"]?@"包到":@"自提",
                       [[self DCRP_STR:dic[@"baozhuang"]] isEqual:@"1"]?@"吨小包": ([[self DCRP_STR:dic[@"baozhuang"]] isEqual:@"2"]?@"小袋":@"散装"),
                       [self DCRP_STR:dic[@"number"]],
                       [self DCRP_STR:dic[@"amount"]],
                       [dic[@"note"] isEqual:@""]?@"无":dic[@"note"],
                       yanshoubianzhun,
                       koufa,
                       [self DCRP_STR:dic[@"unit"]],
                       [self DCRP_STR:dic[@"damount"]],
                       [self DCRP_STR:dic[@"title"]],
                       [self timeChangeWithString:[self DCRP_STR:dic[@"addtime"]]],
                       [self DCRP_STR:dic[@"htid"]],
                       [self DCRP_STR:dic[@"seller_truename"]],
                       [self DCRP_STR:dic[@"seller_address"]],
                       [self DCRP_STR:dic[@"seller_faren"]],
                       [self DCRP_STR:dic[@"seller_dailiren"]],
                       [self DCRP_STR:dic[@"seller_tel"]],
                       [self DCRP_STR:dic[@"seller_accno"]],
                       [self DCRP_STR:dic[@"seller_yinhang"]],
                       [self DCRP_STR:dic[@"seller_shuihao"]],
                       [[self DCRP_STR:dic[@"yunshu"]] isEqual:@"1"]?@"卖家":@"买家"
                       ];
    for (NSInteger i  = 0; i<34; i++) {
        NSString * str1 = [NSString stringWithFormat:@"document.getElementById('%@').innerText = '%@';",arr[i],arr2[i]];
        [webview stringByEvaluatingJavaScriptFromString:str1];
    }
    
    NSString * payType = [self DCRP_STR:dic[@"order_type"]];
    if([payType isEqual:@"A"]){
        NSString * str1 = @"document.getElementById('c_pay_type').innerText = '全款解冻,发货全款解付';";
        [webview stringByEvaluatingJavaScriptFromString:str1];
    }else if([payType isEqual:@"B"]){
        NSString * str1 = @"document.getElementById('c_pay_type').innerText = '全款解冻,装车分批解付';";
        [webview stringByEvaluatingJavaScriptFromString:str1];
    }else if([payType isEqual:@"C"]){
        NSString * str1 = @"document.getElementById('c_pay_type').innerText = '全款解冻,货到分批解付';";
        [webview stringByEvaluatingJavaScriptFromString:str1];
    }else{
        NSString * str1 = @"document.getElementById('c_pay_type').innerText = '全款解冻,完成全部订单全款解付';";
        [webview stringByEvaluatingJavaScriptFromString:str1];
    }
    
    NSString * gg =  [THJTools ContraceGuigeTypeChangeToStrWithType:[self DCRP_STR:dic[@"guige"]]];
    NSString * ggC = [NSString stringWithFormat:@"document.getElementById('c_gg').innerText = '%@';",gg];
    [webview stringByEvaluatingJavaScriptFromString:ggC];
    NSString * orderidC = [NSString stringWithFormat:@"document.getElementById('c_number').innerText = '%@';",self.orderId];
    [webview stringByEvaluatingJavaScriptFromString:orderidC];
    
}
-(NSString*)DCRP_STR:(NSString*)str{
    return   [RSA decryptString:str publicKey:RSA_PubKey];
}
@end
